package de.herberlin.showheader;

import java.io.Serializable;

/**
 *
 * @author Hans Joachim Herbertz
 * @created May 21, 2003
 */
public class ProgressEvent implements Serializable {
	
	public static final int MIN=0;
	public static final int MAX=100;
	
	private Object sender=null;
	private int progress=0;
	private Exception error=null;
	
	public ProgressEvent() {
		super();	
	}
	
	private int adjustProgress(int progr) {
		return Math.max(Math.min(progr,ProgressEvent.MAX),ProgressEvent.MIN);
	
	}
	
	public ProgressEvent(Object sender, int progress) {
		this.sender=sender;
		this.progress=adjustProgress(progress);	
	}
	/**
	 * Returns the progress.
	 * @return int
	 */
	public int getProgress() {
		return progress;
	}

	/**
	 * Returns the sender.
	 * @return Object
	 */
	public Object getSender() {
		return sender;
	}

	/**
	 * Sets the progress.
	 * @param progress The progress to set
	 */
	public void setProgress(int progress) {
		this.progress = adjustProgress(progress);
	}

	/**
	 * Sets the sender.
	 * @param sender The sender to set
	 */
	public void setSender(Object sender) {
		this.sender = sender;
	}
	
	public String toString() {
		return "Sender="+sender+ " progress="+progress;	
	}

	/**
	 * @return
	 */
	public Exception getError() {
		return error;
	}

	/**
	 * @param exception
	 */
	public void setError(Exception exception) {
		error = exception;
	}

}
